package cn.xhh.dailyreview.client;

import java.util.List;

import cn.xhh.dailyreview.client.utils.Result;

import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

@RemoteServiceRelativePath("s")
public interface Service extends RemoteService {
	
	/**
	 * @param email login email
	 * @param passwd login password (encrypted)
	 * @return <code>SUCCESS</code>: login succeeded, and the user level 
	 * is stored in <code>result.getValue("userLevel")</code>.<br/>
	 * <code>FAILURE</code>: incorrect email or password.<br/>
	 * <code>OTHER_A</code>: user is restricted.<br/>
	 * <code>OTHER_B</code>: user is not confirmed yet.
	 */
	Result login(String email, String passwd);
	
	/**
	 * @return always <code>SUCCESS</code>
	 */
	Result logout();
	
	/**
	 * @return <code>SUCCESS</code>: has logged in already 
	 * (login info saved in Session), <br/>
	 * and the user email is stored in 
	 * <code>result.getValue("email") and the user level in
	 * <code>result.getValue("userLevel")</code>;<br/>
	 * otherwise: not signed in.
	 */
	Result checkLogin();
	
	/**
	 * Save the review into database
	 * 
	 * @param reviews the content of the review to be saved. 
	 * must have the length of Review.getItemsNumber().
	 * @return <code>true</code>: saving succeeded. <code>false</code>: saving failed.
	 */
	boolean saveReview(List<String> reviews);

	/**
	 * Submit a registration for the given email.
	 * @param force <code>true</code>: re-submit and send email notification if the email
	 * has submitted before and not confirmed.
	 * @return <code>SUCCESS</code>: registration submitted and email sent 
	 * with the confirmation link.<br/>
	 * <code>VALUES_EXIST</code>: email exists, user restricted or maybe "Forgot Password"?<br/>
	 * <code>FAILURE</code>: registration with the email has submitted before
	 * (with <code>force</code> being <code>false</code>).
	 */
	Result submitRegistration(String email, boolean force);
	
	/**
	 * Submit a Forgot Password request: generate a confirmation code for the user 
	 * and send him an email with the link to reset password.<br/>
	 * Notice: if the user has not confirmed his account yet, an email 
	 * would be sent to him with the confirmation link.
	 * @param email
	 * @return <code>SUCCESS</code>: request handled and email sent with 
	 * the link to reset password.<br/>
	 * <code>FAILURE</code>: email does not exist.<br/>
	 * <code>OTHER_A</code>: user restricted.<br/>
	 */
	Result submitForgotPasswd(String email);
	
	/**
	 * Check if the email and code about the registration (or reset password) are correct.
	 * @param email email for confirmation
	 * @param code code for confirmation
	 * @return <code>SUCCESS</code>: confirmation allowed.<br/>
	 * <code>FAILURE</code>: user restricted or code is incorrect.<br/>
	 * <code>OTHER_A</code>: user not exist: maybe deleted for confirming too late.
	 */
	Result checkSetup(String email, String code);

	/**
	 * Confirm (or reset password) for the user.
	 * @param email user to be confirmed
	 * @param encrPwd the encrypted password to be setup for the user
	 * @return <code>SUCCESS</code>: user confirmed and info logged into session.<br/>
	 * <code>FAILURE</code>: user does not exist.<br/>
	 * <code>OTHER_A</code>: user restricted.
	 */
	Result setupUser(String email, String encrPwd);

	/**
	 * @return the email of the signed-in user stored in Session
	 */
	String getUserEmail();

}
